package com.fowo.api.service.handleWork;

import cn.hutool.core.bean.BeanUtil;
import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.fowo.api.datainterface.util.k3cloud.domain.Authentication;
import com.fowo.api.datainterface.util.k3cloud.domain.BillSave;
import com.fowo.api.entity.BdRate;
import com.fowo.api.entity.ReportFormsPushNotes;
import com.fowo.api.entity.ShopInfo;
import com.fowo.api.entity.ShopProfitReport;
import com.fowo.api.model.shop.profit.report.ShopProfitReportItemVo;
import com.fowo.api.model.shop.profit.report.ShopProfitReportPushJindieAction;
import com.fowo.api.model.shop.profit.report.ShopProfitReportSearchParamPo;
import com.fowo.api.service.handleWork.jindieEntity.jindieResult;
import com.fowo.api.service.handleWork.jindieEntity.jindieVoucher2;
import com.fowo.api.service.impl.BdRateServiceImpl;
import com.fowo.api.service.impl.ReportFormsPushNotesServiceImpl;
import com.fowo.api.service.impl.ShopInfoServiceImpl;
import com.fowo.api.service.impl.ShopProfitReportServiceImpl;
import com.fowo.api.util.LocalDateUtils;
import org.springframework.stereotype.Component;
import org.springframework.util.Assert;

import javax.annotation.Resource;
import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Map;

@Component
public class shopProfitReportPushJindie implements ShopProfitReportPushJindieAction {

    @Resource
    private ShopProfitReportServiceImpl shopProfitReportService;
    private static final Authentication auth=new Authentication("64e8964fb4af0d","Administrator","a@123456");

    private static final K3CloudTemplate k3loudTemplate=new K3CloudTemplate("http://121.225.97.82:8001/K3cloud/",auth);

    @Resource
    private ReportFormsPushNotesServiceImpl reportFormsPushNotesService;
    @Resource
    private ShopInfoServiceImpl shopInfoService;
    @Resource
    private BdRateServiceImpl bdRateService;

    @Override
    public synchronized void run(Long id) throws Exception {
        ShopProfitReport byId = shopProfitReportService.getById(id);
        Date firstDate = LocalDateUtils.firstDayOfMonth(byId.getPostedDateLocale());
        //最后一天
        Date endDate = LocalDateUtils.lastDayOfMonth(byId.getPostedDateLocale());
        ShopProfitReportSearchParamPo search =new ShopProfitReportSearchParamPo();
        search.setSid(byId.getSid());
        search.setPostedDateLocaleStart(firstDate);
        search.setPostedDateLocaleEnd(endDate);
        Page<ShopProfitReportItemVo> shopProfitReportItemVoPage = shopProfitReportService.pageSearch(search);

        List<ReportFormsPushNotes> list = reportFormsPushNotesService.list(Wrappers.<ReportFormsPushNotes>query().lambda()
                .eq(ReportFormsPushNotes::getReportFormsMonthly, LocalDateUtils.format(byId.getPostedDateLocale(), LocalDateUtils.DATE_PATTERN1))
                .eq(ReportFormsPushNotes::getShopName, byId.getSid())
        );
        Assert.isTrue(list.size()>0?list.get(0).getPushStatus().equals("推送失败"):true,"已经推送,"+byId.getStoreName());
        ReportFormsPushNotes   reportFormsPushNotes=new ReportFormsPushNotes();
        reportFormsPushNotes.setReportFormsMonthly(shopProfitReportItemVoPage.getRecords().get(0).getPostedDateLocale());
        reportFormsPushNotes.setShopName(shopProfitReportItemVoPage.getRecords().get(0).getSid()+"");
        reportFormsPushNotes.setPushStatus("推送失败");
        boolean aLong = reportFormsPushNotesService.save(reportFormsPushNotes);
        //查询关联的店铺信息
        ShopInfo one = shopInfoService.getOne(Wrappers.<ShopInfo>query().lambda().eq(ShopInfo::getShopCode, byId.getSid()));
        Assert.notNull(one,"店铺信息不存在!");
        Assert.isTrue(one.getJindieShopCode()!=null,"店铺没有绑定金蝶的店铺编码!");
        String bumen="";
        String shiyebu="";
        //判断是义乌还是深圳
        if(byId.getStoreName().contains("深圳")){
            shiyebu="SYB01";
            bumen="BM000024";
        }else{
            shiyebu="SYB02";
            bumen="BM000023";
        }
        pushJinDie1(shopProfitReportItemVoPage.getRecords().get(0),endDate,reportFormsPushNotes,one.getJindieShopCode(),bumen,shiyebu);
    }

    private void pushJinDie1(ShopProfitReportItemVo itemVo,Date endDate,ReportFormsPushNotes reportFormsPushNotes,String shopCode,String bumen,String shiyebu) {
        String bibie=bizhong(itemVo.getCurrencyCode());

        BdRate one = bdRateService.getOne(Wrappers.<BdRate>query()
                .lambda().eq(BdRate::getCode, bibie));
        Assert.notNull(one,"当前类别在汇率表中不存在!");
        //获取日期
        int month = endDate.getMonth()+1;
        String yuefen=month+"月份";

        BillSave billSave = new BillSave("GL_VOUCHER");
        jindieVoucher2 jindieVoucher=new  jindieVoucher2();
        jindieVoucher.setIsAutoAdjustField("true");
        jindieVoucher.setIsEntryBatchFill("true");
        jindieVoucher.setNumberSearch("true");
        jindieVoucher.setIsControlPrecision("false");
        jindieVoucher2.ModelDTO  modelDTO=new jindieVoucher2.ModelDTO();
        modelDTO.setFvoucherid(0);
        //账簿
        jindieVoucher2.ModelDTO.FAccountBookIDDTO FAccountBookIDDTO=new  jindieVoucher2.ModelDTO.FAccountBookIDDTO();
        FAccountBookIDDTO.setFNumber("002");
        modelDTO.setFAccountBookID(FAccountBookIDDTO);
        //日期
//        modelDTO.setFDate(LocalDateUtils.format(endDate,LocalDateUtils.DATE_PATTERN));//日期
        modelDTO.setFDate(LocalDateUtils.format(endDate,LocalDateUtils.DATE_PATTERN));
        //凭证字
        jindieVoucher2.ModelDTO.FVOUCHERGROUPIDDTO FVOUCHERGROUPIDDTO=new jindieVoucher2.ModelDTO.FVOUCHERGROUPIDDTO();
        FVOUCHERGROUPIDDTO.setFNumber("PRE001");
        modelDTO.setFvouchergroupid(FVOUCHERGROUPIDDTO);
        modelDTO.setFvouchergroupno("1");
        modelDTO.setFDocumentStatus("Z");
        List<jindieVoucher2.ModelDTO.FEntityDTO> list=new ArrayList<>();

        BigDecimal bj=one.getRateNum();
        //销售总额
//        BigDecimal xiaoshouAdd =KeepOne(itemVo.getTotalSalesAmount().subtract(itemVo.getTotalSalesRefunds()),bj)
//                        .add(KeepOne(itemVo.getShippingCredits(),bj)).
//                        add(KeepOne(itemVo.getFbaInventoryCredit(),bj)).
//                        add(KeepOne(itemVo.getOtherInAmount(),bj));
        //销售总额原币金额
        BigDecimal xiaoshoue = itemVo.getTotalSalesAmount().abs();
                //getTotalSalesRefunds
        BigDecimal yuanbixiaoshjou =xiaoshoue.add(itemVo.getTotalSalesRefunds())
                                    .add(itemVo.getPromotionalRebates())
                                    .add(itemVo.getShippingCredits())
                                    .add(itemVo.getOtherInAmount());


        //销售额转化成人民币的金额
        BigDecimal xiaoshouAdd=KeepOne(xiaoshoue,bj)
                .add(KeepOne(itemVo.getTotalSalesRefunds(),bj))
                .add(KeepOne(itemVo.getPromotionalRebates(),bj))
                .add(KeepOne(itemVo.getShippingCredits(),bj))
                .add(KeepOne(itemVo.getOtherInAmount(),bj));
//        itemVo.getFbaInventoryCredit()
//        BigDecimal xiaoshouAdd=KeepOne(yuanbixiaoshjou,bj);fba_inventory_credit

        //平台费减去费用退款额
        BigDecimal pingtaifei = itemVo.getPlatformFee().abs().subtract(itemVo.getTotalFeeRefunds().abs());
        BigDecimal pingtaifei2 = KeepOne(pingtaifei,bj);
//        KeepOne(itemVo.getPromotionFee().abs().subtract(itemVo.getTotalFeeRefunds()),bj).doubleValue()

        //推广费原币
        BigDecimal subtract1 = itemVo.getPromotionFee().abs().add(itemVo.getSharedCouponFee().abs());

        //推广费用 人民币
        BigDecimal tuiguang = KeepOne(subtract1,bj);

        //调整费用
        BigDecimal adjustments=itemVo.getAdjustments().negate();
        //支出费用
        BigDecimal xiaoshouAdd2 =itemVo.getFbaDeliveryFee().abs()
                                .add(itemVo.getTotalAdsCost().abs())
                                .add(itemVo.getTotalStorageFee().abs())
                                .add(subtract1.abs())//推广费
                                .add(pingtaifei)
                                .add(adjustments)
                                .add(itemVo.getFbaInventoryCredit().negate());

        BigDecimal zhichu=KeepOne(itemVo.getFbaDeliveryFee().abs(),bj)
                            .add(KeepOne(itemVo.getTotalAdsCost().abs(),bj))
                            .add(KeepOne(itemVo.getTotalStorageFee().abs(),bj))
                            .add(tuiguang)
                            .add(pingtaifei2)
                            .add(KeepOne(adjustments,bj))
                            .add(KeepOne(itemVo.getFbaInventoryCredit().negate(),bj));
        //totalPlatformOtherFee
       // itemVo.getTotalPlatformOtherFee();
        //支出费用转人民币
//        BigDecimal zhichu=KeepOne(xiaoshouAdd2,bj);

        //支出费用  getPlatformFee是平台交易佣金
//        BigDecimal xiaoshouAdd2 = KeepOne(itemVo.getFbaDeliveryFee().abs(),bj)
//                    .add(KeepOne(itemVo.getPromotionalRebates().abs(),bj))
//                    .add(KeepOne(itemVo.getPlatformFee().abs(),bj))
//                    .add(KeepOne(itemVo.getTotalAdsCost().abs(),bj))
//                    .add(KeepOne(itemVo.getTotalStorageFee().abs(),bj))
//                    .add(KeepOne(itemVo.getPromotionFee().abs().subtract(itemVo.getTotalFeeRefunds()),bj))
//                    .add(KeepOne(itemVo.getAdjustments().abs(),bj))
//                    .add(KeepOne(itemVo.getSharedCouponFee().abs(),bj));
        //人民币
        BigDecimal subtract = xiaoshouAdd.subtract(zhichu);
        //原币
        BigDecimal subtract2 = yuanbixiaoshjou.subtract(xiaoshouAdd2);

        if(!(subtract.compareTo(BigDecimal.ZERO)==0)){
            jindieVoucher2.ModelDTO.FEntityDTO entity = createEntity("1122.01",subtract.doubleValue(),null,shiyebu,null,shopCode,itemVo.getStoreName(),yuefen,bibie,one,subtract.doubleValue(),subtract2,itemVo.getTotalSalesAmount(),itemVo);
            list.add(entity);
        }
        if(!(itemVo.getFbaDeliveryFee().compareTo(BigDecimal.ZERO)==0)) {
            //fba发货费
            jindieVoucher2.ModelDTO.FEntityDTO entity1 = createEntity("6601.01.01", KeepOne(itemVo.getFbaDeliveryFee().abs(),bj).doubleValue(), null, shiyebu, bumen, shopCode, itemVo.getStoreName(), yuefen,bibie,one,0.0,itemVo.getFbaDeliveryFee().abs(), BigDecimal.valueOf(1.0),itemVo);
            list.add(entity1);
        }
        if(!(itemVo.getTotalAdsCost().compareTo(BigDecimal.ZERO)==0)) {
            //广告费
            jindieVoucher2.ModelDTO.FEntityDTO entity5 = createEntity("6601.01.05", KeepOne(itemVo.getTotalAdsCost().abs(),bj).doubleValue(), null, shiyebu, bumen, shopCode, itemVo.getStoreName(), yuefen,bibie,one,0.0,itemVo.getTotalAdsCost().abs(), BigDecimal.valueOf(1.0),itemVo);
            list.add(entity5);
        }
        if(!(itemVo.getTotalStorageFee().compareTo(BigDecimal.ZERO)==0)) {
            // 仓储费
            jindieVoucher2.ModelDTO.FEntityDTO entity6 = createEntity("6601.01.06", KeepOne(itemVo.getTotalStorageFee().abs(),bj).doubleValue(), null, shiyebu, bumen, shopCode, itemVo.getStoreName(), yuefen,bibie,one,0.0,itemVo.getTotalStorageFee().abs(), BigDecimal.valueOf(1.0),itemVo);
            list.add(entity6);
        }
        if(!(tuiguang.compareTo(BigDecimal.ZERO)==0)) {
            //推广费
            jindieVoucher2.ModelDTO.FEntityDTO entity7 = createEntity("6601.01.07", tuiguang.doubleValue(), null, shiyebu, bumen, shopCode, itemVo.getStoreName(), yuefen,bibie,one,0.0,subtract1.abs(), BigDecimal.valueOf(1.0),itemVo);
            list.add(entity7);
        }
        if(!(pingtaifei2.compareTo(BigDecimal.ZERO)==0)) {
            //交易佣金 平台费用
            jindieVoucher2.ModelDTO.FEntityDTO entity4 = createEntity("6601.01.04", pingtaifei2.doubleValue(), null, shiyebu, bumen, shopCode, itemVo.getStoreName(), yuefen,bibie,one,0.0,pingtaifei, BigDecimal.valueOf(1.0),itemVo);
            list.add(entity4);
        }
        if(!(itemVo.getFbaInventoryCredit().compareTo(BigDecimal.ZERO)==0)) {
            //库存赔偿
            jindieVoucher2.ModelDTO.FEntityDTO entity10 = createEntity("6601.01.09", KeepOne(itemVo.getFbaInventoryCredit().negate(),bj).doubleValue(), null, shiyebu, bumen, shopCode, itemVo.getStoreName(), yuefen,bibie,one,0.0,itemVo.getFbaInventoryCredit().negate(), BigDecimal.valueOf(1.0),itemVo);
            list.add(entity10);
        }
//        if(!(itemVo.getPromotionalRebates().compareTo(BigDecimal.ZERO)==0)) {
//            //促销折扣
//            jindieVoucher2.ModelDTO.FEntityDTO entity2 = createEntity("6601.01.02", KeepOne(itemVo.getPromotionalRebates().abs(),bj).doubleValue(), null, shiyebu, bumen, shopCode, itemVo.getStoreName(), yuefen,bibie,one,0.0,itemVo.getPromotionalRebates().abs(),BigDecimal.valueOf(1.0),itemVo);
//            list.add(entity2);
//        }

//        if(!(itemVo.getTotalSalesRefunds().compareTo(BigDecimal.ZERO)==0)){
//            //退款                                               //promotionalRebates
//            jindieVoucher2.ModelDTO.FEntityDTO entity3 = createEntity("6601.01.03",KeepOne(itemVo.getTotalSalesRefunds().abs(),bj).doubleValue(),null,shiyebu,bumen,shopCode,itemVo.getStoreName(),yuefen,bibie,one,0.0);
//            list.add(entity3);
//        }



        if(!(itemVo.getAdjustments().compareTo(BigDecimal.ZERO)==0)) {
            //调整费   adjustments
            jindieVoucher2.ModelDTO.FEntityDTO entity8 = createEntity("6601.01.08", KeepOne(adjustments,bj).doubleValue(), null, shiyebu, bumen, shopCode, itemVo.getStoreName(), yuefen,bibie,one,0.0,adjustments, BigDecimal.valueOf(1.0),itemVo);
            list.add(entity8);
        }
        if(!(xiaoshoue.compareTo(BigDecimal.ZERO)==0)) {
            //贷方  销售额 totalSalesAmount
            jindieVoucher2.ModelDTO.FEntityDTO entity9 = createEntity("6001.01", null, KeepOne(xiaoshoue,bj).doubleValue(), shiyebu, bumen, shopCode, itemVo.getStoreName(), yuefen,bibie,one,0.0,xiaoshoue, BigDecimal.valueOf(1.0),itemVo);
            list.add(entity9);
        }
        //totalSalesRefunds
        if(!(itemVo.getTotalSalesRefunds().compareTo(BigDecimal.ZERO)==0)) {
            // 收入退款金额
            jindieVoucher2.ModelDTO.FEntityDTO entity10 = createEntity("6001.06", null, KeepOne(itemVo.getTotalSalesRefunds(),bj).doubleValue(), shiyebu, bumen, shopCode, itemVo.getStoreName(), yuefen,bibie,one,0.0,itemVo.getTotalSalesRefunds(), BigDecimal.valueOf(1.0),itemVo);
            list.add(entity10);
        }
        if(!(itemVo.getPromotionalRebates().compareTo(BigDecimal.ZERO)==0)) {
            //促销折扣
            jindieVoucher2.ModelDTO.FEntityDTO entity2 = createEntity("6001.07", null, KeepOne(itemVo.getPromotionalRebates(),bj).doubleValue(), shiyebu, bumen, shopCode, itemVo.getStoreName(), yuefen,bibie,one,0.0,itemVo.getPromotionalRebates(),BigDecimal.valueOf(1.0),itemVo);
            list.add(entity2);
        }
        if(!(itemVo.getShippingCredits().compareTo(BigDecimal.ZERO)==0)) {
            // 运费收入  shippingCredits  买家运费
            jindieVoucher2.ModelDTO.FEntityDTO entity10 = createEntity("6001.02", null, KeepOne(itemVo.getShippingCredits(),bj).doubleValue(), shiyebu, bumen, shopCode, itemVo.getStoreName(), yuefen,bibie,one,0.0,itemVo.getShippingCredits().abs(), BigDecimal.valueOf(1.0),itemVo);
            list.add(entity10);
        }
//        if(!(itemVo.getFbaInventoryCredit().compareTo(BigDecimal.ZERO)==0)) {
//            //主营业务收入-库存赔偿 fbaInventoryCredit
//            jindieVoucher2.ModelDTO.FEntityDTO entity11 = createEntity("6001.03", null, KeepOne(itemVo.getFbaInventoryCredit(),bj).doubleValue(), shiyebu, bumen, shopCode, itemVo.getStoreName(), yuefen,bibie,one,0.0,itemVo.getFbaInventoryCredit().abs(), BigDecimal.valueOf(1.0),itemVo);
//            list.add(entity11);
//        }
        if(!(itemVo.getOtherInAmount().compareTo(BigDecimal.ZERO)==0)) {
            //主营业务收入-其他收入 otherInAmount
            jindieVoucher2.ModelDTO.FEntityDTO entity12 = createEntity("6001.04", null, KeepOne(itemVo.getOtherInAmount(),bj).doubleValue(), shiyebu, bumen, shopCode, itemVo.getStoreName(), yuefen,bibie,one,0.0,itemVo.getOtherInAmount().abs(), BigDecimal.valueOf(1.0),itemVo);
            list.add(entity12);
        }
//        if(!(itemVo.getTotalFeeRefunds().compareTo(BigDecimal.ZERO)==0)) {
//            //主营业务收入-费用退款额 totalFeeRefunds
//            jindieVoucher2.ModelDTO.FEntityDTO entity13 = createEntity("6001.05", null, KeepOne(itemVo.getTotalFeeRefunds(),bj).doubleValue(), shiyebu, bumen, shopCode, itemVo.getStoreName(), yuefen,bibie,one,0.0);
//            list.add(entity13);
//        }
        modelDTO.setFEntity(list);
        jindieVoucher.setModel(modelDTO);
        Map<String, Object> stringObjectMap = BeanUtil.beanToMap(jindieVoucher, false, false);
        billSave.setModel(stringObjectMap);
        String result = k3loudTemplate.executeBillSave(billSave, String.class);
        jindieResult jindieResult = JSONObject.parseObject(result, jindieResult.class);
        if(reportFormsPushNotes==null){
            reportFormsPushNotes=new ReportFormsPushNotes();
        }
        if(jindieResult.getResult().getResponseStatus().getIsSuccess().equals("true")){
            reportFormsPushNotes.setReportFormsMonthly(itemVo.getPostedDateLocale());
            reportFormsPushNotes.setShopName(itemVo.getSid()+"");
            reportFormsPushNotes.setPushStatus("推送完成");
        }else{
            reportFormsPushNotes.setReportFormsMonthly(itemVo.getPostedDateLocale());
            reportFormsPushNotes.setShopName(itemVo.getSid()+"");
            reportFormsPushNotes.setPushStatus("推送失败");
            reportFormsPushNotes.setPushResult(jindieResult.getResult().getResponseStatus().getErrors().get(0).getMessage());
        }
        if(reportFormsPushNotes.getId()==null){
            reportFormsPushNotesService.save(reportFormsPushNotes);
        }else{
            reportFormsPushNotesService.updateById(reportFormsPushNotes);
        }
        if(!jindieResult.getResult().getResponseStatus().getIsSuccess().equals("true")){
            Assert.isTrue(false,"推送失败:"+jindieResult.getResult().getResponseStatus().getErrors().get(0).getMessage());
        }

    }

    private static jindieVoucher2.ModelDTO.FEntityDTO createEntity(String kemu,
                                                                   Double jiefang,
                                                                   Double daifang,
                                                                   String shiyebu,
                                                                   String bumen,
                                                                   String dianpu,
                                                                   String code,
                                                                   String yuefen,
                                                                   String bibie,
                                                                   BdRate one,
                                                                   Double zongjine,
                                                                   BigDecimal yuanbi,
                                                                   BigDecimal xiaoshoue,ShopProfitReportItemVo item
                                                                                ){
        jindieVoucher2.ModelDTO.FEntityDTO fEntityDTO=new jindieVoucher2.ModelDTO.FEntityDTO();
        //科目编码
        jindieVoucher2.ModelDTO.FEntityDTO.FACCOUNTIDDTO FACCOUNTIDDTO=new jindieVoucher2.ModelDTO.FEntityDTO.FACCOUNTIDDTO();
        FACCOUNTIDDTO.setFNumber(kemu);
        fEntityDTO.setFaccountid(FACCOUNTIDDTO);
        //店铺名称
        fEntityDTO.setFexplanation(code+yuefen+"收入确认");
        //币别
        jindieVoucher2.ModelDTO.FEntityDTO.FCURRENCYIDDTO  FCURRENCYIDDTO=new jindieVoucher2.ModelDTO.FEntityDTO.FCURRENCYIDDTO();
        FCURRENCYIDDTO.setFNumber(bibie);//PRE001
        fEntityDTO.setFcurrencyid(FCURRENCYIDDTO);
        //汇率
        jindieVoucher2.ModelDTO.FEntityDTO.FEXCHANGERATETYPEDTO FEXCHANGERATETYPEDTO=new jindieVoucher2.ModelDTO.FEntityDTO.FEXCHANGERATETYPEDTO();
        FEXCHANGERATETYPEDTO.setFNumber("HLTX01_SYS");
        fEntityDTO.setFexchangeratetype(FEXCHANGERATETYPEDTO);
        fEntityDTO.setFexchangerate(0.0);
        fEntityDTO.setFamountfor(yuanbi.doubleValue());
        if(zongjine<0&&xiaoshoue.compareTo(BigDecimal.ZERO)==0&&item.getTotalFeeRefunds().compareTo(BigDecimal.ZERO)==0){
//            fEntityDTO.setFcredit(jiefang);
            fEntityDTO.setFcredit(new BigDecimal(jiefang).abs().doubleValue());//
            fEntityDTO.setFamountfor(yuanbi.abs().doubleValue());
        }else {
            if(kemu.equals("1122.01")&&jiefang<0){

                fEntityDTO.setFcredit(new BigDecimal(jiefang).abs().doubleValue());//
                fEntityDTO.setFamountfor(yuanbi.abs().doubleValue());
            }else {
                fEntityDTO.setFdebit(jiefang);//
                fEntityDTO.setFcredit(daifang);
            }
        }

        //借方金额
//        fEntityDTO.setFexchangerate(one.getRateNum().doubleValue());
//        if(jiefang!=null){
//            fEntityDTO.setFdc(1);
//        }else{
//            fEntityDTO.setFdc(0);
//        }
//        fEntityDTO.setFamountfor(jiefang!=null?jiefang:daifang);//原币金额
        // 贷方金额

        jindieVoucher2.ModelDTO.FEntityDTO.FDetailIDDTO FDetailIDDTO=new jindieVoucher2.ModelDTO.FEntityDTO.FDetailIDDTO();
        //事业部
        if(shiyebu!=null){
            jindieVoucher2.ModelDTO.FEntityDTO.FDetailIDDTO.FDETAILIDFF100003DTO  FDETAILIDFFLEX4DTO=new  jindieVoucher2.ModelDTO.FEntityDTO.FDetailIDDTO.FDETAILIDFF100003DTO();
            FDETAILIDFFLEX4DTO.setFNumber(shiyebu);
            FDetailIDDTO.setFDETAILID__FF100003(FDETAILIDFFLEX4DTO);
            fEntityDTO.setFDetailID(FDetailIDDTO);
        }
        //部门
        if(bumen!=null){
            jindieVoucher2.ModelDTO.FEntityDTO.FDetailIDDTO.FDETAILIDFFLEX5DTO  FDETAILIDFFLEX4DTO=new  jindieVoucher2.ModelDTO.FEntityDTO.FDetailIDDTO.FDETAILIDFFLEX5DTO();
            FDETAILIDFFLEX4DTO.setFNumber(bumen);
            FDetailIDDTO.setFDETAILID__FFLEX5(FDETAILIDFFLEX4DTO);
            fEntityDTO.setFDetailID(FDetailIDDTO);
        }
        //店铺
        if(dianpu!=null){
            jindieVoucher2.ModelDTO.FEntityDTO.FDetailIDDTO.FDETAILIDFF100007DTO  FDETAILIDFF100007DTO=new  jindieVoucher2.ModelDTO.FEntityDTO.FDetailIDDTO.FDETAILIDFF100007DTO();
            FDETAILIDFF100007DTO.setFNumber(dianpu);
            FDetailIDDTO.setFDETAILID__FF100007(FDETAILIDFF100007DTO);
            fEntityDTO.setFDetailID(FDetailIDDTO);
        }
        return fEntityDTO;
    }

    //获取币种
    public  String bizhong(String s){
        String str=null;
        //金蝶的币种
        if(s.equals("USD")){
            str="PRE007";
        }else if(s.equals("CAD")){
            str="PRE008";
        }else if(s.equals("MXN")){
            str="PRE009";
        }else if(s.equals("EUR")){
            str="PRE003";
        }else if(s.equals("GBP")){
            str="PRE006";
        }else if(s.equals("PLN")){
            str="RPE010";
        }else{
            Assert.isTrue(false,"没有找到这个币种!");
        }
        return  str;

    }

    public  BigDecimal KeepOne(BigDecimal bigDecimal,BigDecimal huilv){
        BigDecimal bigDecimal1 =bigDecimal.multiply(huilv).setScale(2, BigDecimal.ROUND_HALF_UP);
        return bigDecimal1;
    }

}
